package com.pactera.madp.cp.controller.sidebar.product;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.product.ProductQueryDto;
import com.pactera.madp.cp.api.dto.track.BehaviorTrackDto;
import com.pactera.madp.cp.service.BehaviorTrackService;
import com.pactera.madp.cp.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 产品管理
 *
 * @author kedongZhang
 * @date 2021/5/26 10:22
 */
@RestController
@AllArgsConstructor
@RequestMapping("/productwechat")
@Slf4j
@Api(value = "productwechat", tags = "侧边栏产品管理")
public class SidebarProductController {

    private final ProductService productService;
    @Resource
    private BehaviorTrackService behaviorTrackService;

    /**
     * 分页查询产品
     *
     * @param page 分页对象
     * @param dto 查询产品传输对象
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询产品")
    public R getProductPage(String wxUserId, Page page, ProductQueryDto dto){
      return productService.getSidebarProductPage(wxUserId, page,dto);
    }

    /**
     * 根据分类id获取上架(已发布)产品列表
     * @param page 分页
     * @param groupId 分类id
     * @return list
     */
    @GetMapping("/index")
    @ApiOperation(value = "根据分类id获取上架(已发布)产品列表")
    public R getPublishedProductListByGroupId(Page page,@RequestParam Integer groupId){
       return productService.getSidebarPublishedProductListByGroupId(page,groupId);
    }

    /**
     * 发送次数统计
     */
    @SysLog("发送侧边栏产品管理次数统计")
    @GetMapping("/send")
    @ApiOperation(value = "发送次数统计")
    public void send(BehaviorTrackDto dto, HttpServletResponse response) throws Exception {
        dto.setEvent("product");
        dto.setProductCountType("recommend");
        behaviorTrackService.handleTrack(dto,response);
    }

}
